package com.example.hellotwo;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import java.text.DecimalFormat;
import java.time.LocalDate;

import javax.security.auth.login.LoginException;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.aa);
//      TextView output=findViewById(R.id.out);
//      output.setText("hello swufe");
//        EditText edit=findViewById(R.id.inp);
//        edit.setText("123");
//        Log.i("11111","开始运行了");
        Button bt=findViewById(R.id.btn);
//        bt.setText("Login");
        bt.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        Log.i("2222","AAAAAAAAA");
        EditText edit=findViewById(R.id.inp);
        float kilo=Float.parseFloat(edit.getText().toString());
        EditText edit2=findViewById(R.id.inp2);
        float height=Float.parseFloat(edit2.getText().toString());
        float b=kilo/(height*height);
        TextView output=findViewById(R.id.out);
        DecimalFormat df = new DecimalFormat("######0.00");
        float bmi= Float.parseFloat(df.format(b));
        if(bmi<20){
            output.setText("结果为："+df.format(b)+"\n偏瘦，要多吃饭啦");
        }
        else if(20<=bmi&&bmi<25){
            output.setText("结果为："+df.format(b)+"\n适中，继续保持身材");
        }
        else if(25<=bmi&&bmi<30){
            output.setText("结果为："+df.format(b)+"\n过重，需要少吃一点咯");
        }
        else if(bmi>=30){
            output.setText("结果为："+df.format(b)+"\n肥胖，需要减肥啦");
        }
    }
}